﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Data.SQLite;

namespace OpenMobileStoreModel
{
    public abstract class Invoice
    {
        private long mId;
        private long mType;
        private long mNr;
        private long mContragentId;
        private DateTime mDtCreated;
        private double mTotal;
        private double mPaid;

        internal Invoice(SQLiteDataReader aReader)
        {
            mId = aReader.GetInt64(0);
            mType = aReader.GetInt64(1);
            if (!aReader.IsDBNull(2)) { mNr = aReader.GetInt64(2); }
            if (!aReader.IsDBNull(3)) { mContragentId = aReader.GetInt64(3); }
            if (!aReader.IsDBNull(4)) { mDtCreated = aReader.GetDateTime(4); }
            if (!aReader.IsDBNull(5)) { mTotal = aReader.GetDouble(5); }
            if (!aReader.IsDBNull(6)) { mPaid = aReader.GetDouble(6); }
        }
    
        public long Id
        {
            get
            {
                return mId;
            }
        }

        public DateTime DtCreated
        {
            get
            {
                return mDtCreated;
            }
        }

        public long Nr
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        public Contragent Contragent
        {
            get
            {
                return Contragent.GetById(this.Id);
            }
        }

        public InvoiceLine[] Lines
        {
            get
            {
                throw new System.NotImplementedException();
            }
        }

        public bool IsOpened
        {
            get
            {
                return (mDtCreated == null);
            }
        }

        public double Total
        {
            get
            {
                return mTotal;
            }
        }

        public double Paid
        {
            get
            {
                return mPaid;
            }
        }

        /// <summary>
        /// Close invoice (i.e set DtCreated).
        /// </summary>
        public void Close()
        {
            throw new System.NotImplementedException();
        }

        /// <summary>
        /// Remove all invoice lines.
        /// Throw StoreException if invoice is closed.
        /// </summary>
        public void Clear()
        {
            throw new System.NotImplementedException();
        }

        /// <summary>
        /// Throw StoreException if invoice is closed.
        /// </summary>
        /// <param name="aProduct"></param>
        /// <param name="aQuantity"></param>
        /// <returns></returns>
        public InvoiceLine AddLine(InvoiceLine aLine)
        {
            throw new System.NotImplementedException();
        }

        
    }
}
